package com.imay.live.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.imay.live.R;
import com.imay.live.model.TabIndicatorModel;
import com.imay.live.view.indicator.FragmentListPageAdapter;
import com.imay.live.view.indicator.IndicatorViewPager;

import java.util.List;

/**
 * Created by  nick on 2017/3/24 0024.
 */

public class IndicatorFragmentAdapter extends IndicatorViewPager.IndicatorFragmentPagerAdapter{

    private List<Fragment> fragmentList;
    private List<TabIndicatorModel> mTabModels;
    private LayoutInflater inflate;
    public IndicatorFragmentAdapter(Context context,FragmentManager fragmentManager, List<Fragment> fragments, List<TabIndicatorModel> mTabModels) {
        super(fragmentManager);
        this.fragmentList=fragments;
        this.mTabModels=mTabModels;
        inflate = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }

    @Override
    public View getViewForTab(int position, View convertView, ViewGroup container) {
        TabIndicatorModel model = mTabModels.get(position);
        if (convertView == null) {
            convertView = inflate.inflate(R.layout.view_indicator_tab, container, false);
        }
        //这里先简单处理,tab 数量不多,不存在重用的问题.
        TextView textView = (TextView) convertView.findViewById(R.id.tv_notice_indicator);
        ImageView iv_notice_unread = (ImageView) convertView.findViewById(R.id.iv_notice_unread);
        textView.setText(model.getTitle());
        iv_notice_unread.setVisibility(model.isUnread()?View.VISIBLE:View.GONE);
        return convertView;
    }

    @Override
    public Fragment getFragmentForPage(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getItemPosition(Object object) {
        return FragmentListPageAdapter.POSITION_NONE;
    }

}
